package cn.source.system.controller;

import cn.source.common.annotation.Log;
import cn.source.common.constant.HttpStatus;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.NavCategory;
import cn.source.system.service.INavCategoryService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: source-vue
 * @ClassName: NavCategoryController
 * @description: 导航分类Controller
 * @author: 诗涵
 * @create: 2024-02-20 16:58
 */
@RestController
@RequestMapping("/nav/category")
@AllArgsConstructor
public class NavCategoryController extends BaseController {
    private final INavCategoryService navCategoryService;

    /**
     * 查询导航分类列表
     */
    @PreAuthorize("@ss.hasPermi('nav:category:list')")
    @GetMapping("/list")
    public AjaxResult list(NavCategory navCategory) {
        List<NavCategory> list = navCategoryService.selectNavCategoryList(navCategory);
        return new AjaxResult(HttpStatus.SUCCESS, "查询成功", list);
    }

    /**
     * 新增导航分类
     */
    @PreAuthorize("@ss.hasPermi('nav:category:add')")
    @Log(title = "导航分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NavCategory navCategory) {
        return toAjax(navCategoryService.insertNavCategory(navCategory));
    }

    /**
     * 修改导航分类
     */
    @PreAuthorize("@ss.hasPermi('nav:category:update')")
    @Log(title = "导航分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NavCategory navCategory) {
        return toAjax(navCategoryService.updateNavCategory(navCategory));
    }

    /**
     * 获取导航分类详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(navCategoryService.selectNavCategoryById(id));
    }

    /**
     * 删除导航分类
     */
    @PreAuthorize("@ss.hasPermi('nav:category:delete')")
    @Log(title = "导航分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(navCategoryService.deleteNavCategoryByIds(ids));
    }
}
